package com.appview;

import com.util.Config;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by QiHuang on 2015/10/27.
 * 退出选项
 */
public class ExitTip extends JFrame implements ActionListener {
    private JLabel jLabel;
    private JButton jButton1, jButton2, jButton3;
    private JPanel jPanel1, jPanel2;
    public ExitTip() {

    }

    public void openView() {
        initComponent();
        jPanel1.add(jLabel);
        jPanel1.setLayout(new FlowLayout(FlowLayout.CENTER));
        jPanel2.add(jButton1);
        jPanel2.add(jButton2);
        jPanel2.add(jButton3);
        jPanel2.setLayout(new FlowLayout(FlowLayout.CENTER));

        add(jPanel1, BorderLayout.NORTH);
        add(jPanel2, BorderLayout.CENTER);
//        setLayout(new GridLayout(2, 1));
        setSize(250, 120);
        setVisible(true);
        setLocation(400, 200);
        setResizable(false);
        setTitle("系统操作");
        setAlwaysOnTop(true);
        setFocusable(true);
    }
    private void initComponent() {
        jLabel = new JLabel("选择操作");
        jButton1 = new JButton("注销");
        jButton2 = new JButton("退出");
        jButton3 = new JButton("返回");

        jPanel1 = new JPanel();
        jPanel2 = new JPanel();

        jButton1.addActionListener(this);
        jButton2.addActionListener(this);
        jButton3.addActionListener(this);
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == jButton1) {
            //注销
            this.dispose();
            if (Config.getLoginType() == 2) {
                MainView.getMainView().dispose();
                Config.removeType();
            } else {
                UserView.getUserView().dispose();
            }
            Config.removeLoginType();
            new StuLogin();

        } else if (e.getSource() == jButton2) {
            //退出
            this.dispose();
            if (Config.getLoginType() == 2) {
                MainView.getMainView().dispose();
                Config.removeType();
            } else {
                UserView.getUserView().dispose();
            }
        } else if (e.getSource() == jButton3) {
            //返回
            this.dispose();
        }
    }
}
